home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3.iso / chapte22 / ex6.c < prev    next >
C/C++ Source or Header  |  1995-05-27  |  4KB  |  115 lines

  1. #include <genstub.c>
  2. #include <winnls.h>
  3.  
  4. // Define code pages typically available.
  5. typedef struct CPListElementtag {
  6.     UINT uCPId;
  7.     char szCPName[40];
  8. } CPListElement;
  9.  
  10. CPListElement codepages [50] = {
  11.                         037, "EBCDIC",
  12.                         437, "MS-DOS United States",
  13.                         500, "EBCDIC 500V1",
  14.                         708, "Arabic (ASMO 708)",
  15.                         709, "Arabic (ASMO 449+, BCON V4)",
  16.                         710, "Arabic (Transparent Arabic)",
  17.                         720, "Arabic (Transparent ASMO)",
  18.                         737, "Greek (formerly 437G)",
  19.                         775, "Baltic",
  20.                         850, "MS-DOS Multilingual (Latin I)",
  21.                         852, "MS-DOS Slavic (Latin II)",
  22.                         855, "IBM Cyrillic (primarily Russian)",
  23.                         857, "IBM Turkish",
  24.                         860, "MS-DOS Portuguese",
  25.                         861, "MS-DOS Icelandic",
  26.                         862, "Hebrew",
  27.                         863, "MS-DOS Canadian-French",
  28.                         864, "Arabic",
  29.                         865, "MS-DOS Nordic",
  30.                         866, "MS-DOS Russian",
  31.                         869, "IBM Modern Greek",
  32.                         874, "Thai",
  33.                         875, "EBCDIC",
  34.                         932, "Japan",
  35.                         936, "Chinese (PRC, Singapore)",
  36.                         949, "Korean",
  37.                         950, "Chinese (Taiwan, Hong Kong) ",
  38.                        1026, "EBCDIC",
  39.                        1200, "Unicode (BMP of ISO 10646)",
  40.                        1250, "Windows 3.1 Eastern European ",
  41.                        1251, "Windows 3.1 Cyrillic",
  42.                        1252, "Windows 3.1 US (ANSI)",
  43.                        1253, "Windows 3.1 Greek",
  44.                        1254, "Windows 3.1 Turkish",
  45.                        1255, "Hebrew",
  46.                        1256, "Arabic",
  47.                        1257, "Baltic",
  48.                        1361, "Korean (Johab)",
  49.                       10000, "Macintosh Roman",
  50.                       10001, "Macintosh Japanese",
  51.                       10006, "Macintosh Greek I",
  52.                       10007, "Macintosh Cyrillic",
  53.                       10029, "Macintosh Latin 2",
  54.                       10079, "Macintosh Icelandic",
  55.                       10081, "Macintosh Turkish",
  56.                           0 ,"Undefined"
  57.                     };
  58.  
  59. BOOL CALLBACK EnumCodePages( LPWSTR lpCPString )
  60. {
  61.     TCHAR  szBuffer[128];
  62.     DWORD  wCodePage;
  63.     CPINFO cpInfo;
  64.     int i = 0;
  65.  
  66.     // Convert to ANSI to parse with C functions.
  67.     WideCharToMultiByte( CP_ACP, 0, lpCPString, -1, szBuffer, 127, NULL, NULL );
  68.  
  69.     wsprintf( szBuffer, "%s", lpCPString);
  70.     sscanf( szBuffer, "%u", &wCodePage );
  71.  
  72.     while ( (codepages[i].uCPId != 0) && (codepages[i].uCPId != wCodePage ) )
  73.         i++;
  74.  
  75.     wsprintf( szBuffer, "Code Page = %d, Name = %s", wCodePage,
  76.               codepages[i].szCPName );
  77.  
  78.     if ( IsValidCodePage( wCodePage ) )
  79.     {
  80.        char szMore[32];
  81.        GetCPInfo( wCodePage, &cpInfo );
  82.        wsprintf( szMore, " Max Char Width: %d", cpInfo.MaxCharSize );
  83.        lstrcat( szBuffer, szMore );
  84.     }
  85.     else
  86.        lstrcat( szBuffer, " Invalid Code Page" );
  87.  
  88.     MessageBox( NULL, szBuffer, "Code Page Enumeration", MB_OK );
  89.     return TRUE;
  90. }
  91.  
  92. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  93. {
  94.     static BOOL bFlag = CP_INSTALLED;
  95.     switch (uMsg)
  96.     {
  97.             case WM_COMMAND:       /* process menu items */
  98.                     switch ( LOWORD( wParam )  )
  99.                     {
  100.                         case IDM_TEST:  // clear window and display screen.
  101.                               EnumSystemCodePages( EnumCodePages, CP_INSTALLED );
  102.                               break;
  103.                         case IDM_EXIT:
  104.                               DestroyWindow( hWnd );
  105.                               break;
  106.                     }
  107.                     break;
  108.             case WM_DESTROY:
  109.                     PostQuitMessage( 0 );
  110.                     break;
  111.            default:
  112.                  return (DefWindowProc(hWnd, uMsg, wParam, lParam));
  113.     }
  114.     return (NULL);
  115. }